//
//  ReportDeviceAlarmPointCell.m
//  efairy
//
//  Created by 李锋 on 2019/3/20.
//  Copyright © 2019年 East. All rights reserved.
//

#import "ReportDeviceAlarmPointCell.h"

@implementation ReportDeviceAlarmPointCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initView];
    }
    return self;
}

//定义cell的宽度
- (void)setFrame:(CGRect)frame {
    frame.origin.x += 8;//8 为margin 值
    frame.size.width -= 2 * 8;
    [super setFrame:frame];
}


-(void)initView{
    

    _deviceName = [[UILabel alloc]init];//设备名称
    _deviceName.textColor = ColorFromRGB(0x333333);
    _deviceName.font = [UIFont boldSystemFontOfSize:16.f];
   
    _line = [[UIView alloc]init];
    _line.backgroundColor = ColorFromRGB(0xe5e5e5);
    
    
    _deviceTypeTitle = [[UILabel alloc]init];   // 设备类型
    _deviceTypeTitle.text = @"设备类型:";
    _deviceTypeTitle.textColor = ColorFromRGB(0x333333);
    _deviceTypeTitle.font = [UIFont systemFontOfSize:14.f];
    
    _deviceType = [[UILabel alloc]init];
    _deviceType.textColor = ColorFromRGB(0x666666);
    _deviceType.font = [UIFont systemFontOfSize:14.f];
    _deviceType.numberOfLines = 0;
    
    
    _alarmTypeTitle = [[UILabel alloc]init];   //报警类型
    _alarmTypeTitle.text = @"火警/预警/故障:";
    _alarmTypeTitle.textColor = ColorFromRGB(0x333333);
    _alarmTypeTitle.font = [UIFont systemFontOfSize:14.f];
    
    _alarmType = [[UILabel alloc]init];   //报警类型
    _alarmType.textColor = ColorFromRGB(0x666666);
    _alarmType.font = [UIFont systemFontOfSize:14.f];
    
    _deviceUUIDTitle = [[UILabel alloc]init];  //设备uuid
    _deviceUUIDTitle.text = @"设备uuid:";
    _deviceUUIDTitle.textColor = ColorFromRGB(0x333333);
    _deviceUUIDTitle.font = [UIFont systemFontOfSize:14.f];
    
    _deviceUUID = [[UILabel alloc]init];
    _deviceUUID.textColor = ColorFromRGB(0x666666);
    _deviceUUID.font = [UIFont systemFontOfSize:14.f];
    
    _deviceAddressTitle = [[UILabel alloc]init];//设备地址
    _deviceAddressTitle.text = @"设备地址:";
    _deviceAddressTitle.textColor = ColorFromRGB(0x333333);
    _deviceAddressTitle.font = [UIFont systemFontOfSize:14.f];
    
    _deviceAddress = [[UILabel alloc]init];// 报表生成时间
    _deviceAddress.textColor = ColorFromRGB(0x666666);
    _deviceAddress.font = [UIFont systemFontOfSize:14.f];
    _deviceAddress.numberOfLines = 0;
    [self.contentView sd_addSubviews:@[_deviceName,_line,_deviceTypeTitle,_deviceType,_alarmTypeTitle,_alarmType,_deviceUUIDTitle,
                                       _deviceUUID,_deviceAddressTitle,_deviceAddress]];
    
    _deviceName.sd_layout.widthIs(SCREEN_WIDTH-16).heightIs(40).leftSpaceToView(self.contentView, 12).topSpaceToView(self.contentView, 0);
    _line.sd_layout.widthIs(SCREEN_WIDTH-16).heightIs(1).topSpaceToView(_deviceName, 0);
    _deviceTypeTitle.sd_layout.widthIs(74).heightIs(14).leftSpaceToView(self.contentView, 12).topSpaceToView(_line, 12);
    _deviceType.sd_layout.widthIs(SCREEN_WIDTH-16-74).topEqualToView(_deviceTypeTitle).leftSpaceToView(_deviceTypeTitle, 0).rightSpaceToView(self.contentView, 12).autoHeightRatio(0);
    _alarmTypeTitle.sd_layout.widthIs(112).heightIs(14).leftSpaceToView(self.contentView, 12).topSpaceToView(_deviceType, 12);
    _alarmType.sd_layout.widthIs(SCREEN_WIDTH-16-118).topEqualToView(_alarmTypeTitle).leftSpaceToView(_alarmTypeTitle, 0).rightSpaceToView(self.contentView, 12).heightIs(14);
    
    _deviceUUIDTitle.sd_layout.widthIs(74).heightIs(14).leftSpaceToView(self.contentView, 12).topSpaceToView(_alarmType, 12);
    _deviceUUID.sd_layout.widthIs(SCREEN_WIDTH-16-74).topEqualToView(_deviceUUIDTitle).leftSpaceToView(_deviceUUIDTitle, 0).rightSpaceToView(self.contentView, 12).heightIs(14);
    
    _deviceAddressTitle.sd_layout.widthIs(74).heightIs(38).leftSpaceToView(self.contentView, 12).topSpaceToView(_deviceUUIDTitle, 0);
    _deviceAddress.sd_layout.widthIs(SCREEN_WIDTH-16-74).topSpaceToView(_deviceUUIDTitle, 12)
    .leftSpaceToView(_deviceAddressTitle, 0).rightSpaceToView(self.contentView, 12).autoHeightRatio(0);
    [self setupAutoHeightWithBottomView:_deviceAddress bottomMargin:12];
    
    
}



-(void)setDataModel:(DeviceAlarmInfoModel *)data{
    if(data != nil){
        _deviceName.text= data.efairydevice_name;
        _deviceType.text = data.efairydevice_device_type?data.efairydevice_device_type:@"未知";
        NSString *alarmTexts= [NSString stringWithFormat:@"%@/%@/%@",
                               data.efairydevice_alarm_times?data.efairydevice_alarm_times:@"0",
                               data.efairydevice_early_warning_times?data.efairydevice_early_warning_times:@"0",
                               data.efairydevice_trouble_times?data.efairydevice_trouble_times:@"0"];
        NSMutableAttributedString *alarmText = [[NSMutableAttributedString alloc] initWithString:alarmTexts];
        
        [alarmText addAttribute:NSForegroundColorAttributeName value:ColorFromRGB(0xFF0000) range:[alarmTexts rangeOfString:data.efairydevice_alarm_times?data.efairydevice_alarm_times:@"0"]];
        [alarmText addAttribute:NSForegroundColorAttributeName value:ColorFromRGB(0xFF7200) range:[alarmTexts rangeOfString:data.efairydevice_early_warning_times?data.efairydevice_early_warning_times:@"0"]];
        [alarmText addAttribute:NSForegroundColorAttributeName value:ColorFromRGB(0xFFB900) range:[alarmTexts rangeOfString:data.efairydevice_trouble_times?data.efairydevice_trouble_times:@"0"]];
      
        _alarmType.attributedText = alarmText;
        _deviceUUID.text = data.efairydevice_uuid;
        _deviceAddress.text =(data.efairydevice_address && data.efairydevice_address.length > 0)? data.efairydevice_address :@"暂无";
    }
}

@end
